package com.tsunami.authority.enums.admin;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tsunami.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @Classname TenantType
 * @Description TODO
 * @Date 2021-12-02 17:46
 * @Created by lx
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "TenantType", description = "租户类型-枚举")
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum TenantType implements BaseEnum {
    /**
     * T="try"
     */
    T("试用","T"),
    /**
     * F="formal"
     */
    F("正式","F"),
    /**
     * V="vip"
     */
    V("VIP","VIP"),
    /**
     * SV="svip"
     */
    SV("SVIP","SVIP"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;
    @ApiModelProperty(value = "编码")
    private String code;

    public static TenantType match(String val, TenantType def) {
        for (TenantType enm : TenantType.values()) {
            if (enm.name().equalsIgnoreCase(val)) {
                return enm;
            }
        }
        return def;
    }

    public static TenantType get(String val) {
        return match(val, null);
    }

    public boolean eq(String val) {
        return this.name().equalsIgnoreCase(val);
    }

    public boolean eq(TenantType val) {
        if (val == null) {
            return false;
        }
        return eq(val.name());
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    public static TenantType getEnum(String code) {
        for (final TenantType item : TenantType.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }
        return null;
    }

    public static void main(String[] args) {

        System.out.println(TenantType.get("V"));
    }
}
